package com.lingyue.commons.validator;

import java.util.regex.Pattern;

/**
 * Created by IntelliJ IDEA.
 *
 * @Description: TODO
 * @Author: BaiJinhua
 * @Date: 2019/11/27 0:51
 * @See: com.lingyue.common.tools
 * @Version: 1.0
 * Copyright: Copyright (c) 2019
 */
public class VerifyUtil {

    /**
     * 整数 和 0
     */
    private static final Pattern integer = Pattern.compile("^(0|-?[1-9]\\d*)$");

    /**
     * 浮点数
     */
    private static final Pattern decimal = Pattern.compile("^-?([1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*|0?\\.0+)$");

    /**
     * 验证是否是整数型和0
     * @param value
     * @return
     */
    public static boolean isInteger(String value) {
        return integer.matcher(value).matches();
    }

    /**
     * 验证是否是浮点型
     * @param value
     * @return
     */
    public static boolean isDecimal(String value){
        return decimal.matcher(value).matches();
    }
}
